package com.yunduo.module.FileStore;

import com.yunduo.common.YunDuoUtils;
import com.yunduo.module.FileStore.impl.LocalFileStore;
import com.yunduo.module.FileStore.impl.OssStore;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 使用策略模式生成不同配置对象到容器中
 */
@Configuration
public class FileContext {

    @Value("${yunduo.fileStore}")
    private String context;

    @Bean
    public FileStore fileStore(){
        FileStore fileStore = null;
        switch (context){
            case "Oss" : fileStore = new OssStore();
                break;
            case "Local" : fileStore = new LocalFileStore();
                break;
            default:
                System.err.println("存储配置加载失败,检查配置");
                YunDuoUtils.exit();
        }
        return fileStore;
    }
}
